Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Send Percy screenshots via npm script (not Jest) #3009

Merged
merged 2 commits into from
Nov 18, 2022

Conversation

colinrotherham
Copy link
Contributor

@colinrotherham colinrotherham commented Nov 14, 2022

This PR moves our Percy screenshots out of Jest following a recent conversation

Discussion regarding #2864: “I was originally thinking of trying to split the Percy screenshotting out from Jest as the screenshot ‘tests’ aren’t really tests at all.”

This has added another big speed up to our checks

Regression checks via GitHub Actions workflow

@colinrotherham colinrotherham requested a review from a team as a code owner November 14, 2022 18:29
@colinrotherham colinrotherham added this to Needs review 🔍 in Design System Sprint Board via automation Nov 14, 2022
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3009 November 14, 2022 18:30 Inactive
@colinrotherham colinrotherham changed the base branch from review-app-esm to main November 15, 2022 09:16
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3009 November 15, 2022 09:16 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3009 November 15, 2022 10:46 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3009 November 15, 2022 10:56 Inactive
@colinrotherham colinrotherham changed the title Send Percy screenshots via npm script Send Percy screenshots via npm script (not Jest) Nov 15, 2022
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3009 November 15, 2022 11:18 Inactive
@@ -140,7 +140,13 @@ jobs:

- description: JavaScript component tests
name: test-component
run: npx percy exec -- jest --color --selectProjects "JavaScript component tests"
run: npx jest --color --maxWorkers=2 --selectProjects "JavaScript component tests"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the CPU load from the @percy/puppeteer Chromium tabs we can now run JavaScript component tests with 2x workers

We use the same flag for JavaScript behaviour tests above

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3009 November 15, 2022 12:48 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3009 November 15, 2022 12:50 Inactive
uses: ./.github/workflows/actions/install-node

- name: Start review application
run: npm run serve &
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starts the review app in the background using &


env:
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}
PORT: 8888
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review app uses port 3000 but our Puppeteer helpers want 8888

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3009 November 15, 2022 12:59 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3009 November 15, 2022 13:07 Inactive
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3009 November 15, 2022 13:13 Inactive
PERCY_TOKEN: ${{ secrets.PERCY_TOKEN }}

regression:
name: Regression checks
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make it clearer that the checks happen 'in Percy' rather than as part of this action? Maybe naming this something like 'Send screenshots to Percy'?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah so this is the job name "Regression checks" which might include others in future?

The step name on line 189 says "Send screenshots to Percy"

Happy to make them match though

@@ -137,10 +137,12 @@ jobs:
- description: JavaScript behaviour tests
name: test-behaviour
run: npx jest --color --maxWorkers=2 --selectProjects "JavaScript behaviour tests"
cache: .cache/jest
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this related to the other changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was me noticing that we restore the .cache/jest directory for all four Verify jobs

But didn't necessarily need it for:

npm run build:package
npm run build:dist

As we saw in the Windows runners often "restoring the cache" was slower than not having it.

The code was simpler before so I'll put it back

@@ -2,7 +2,7 @@ const { componentNameToJavaScriptClassName } = require('./helper-functions.js')
const { renderHtml } = require('./jest-helpers.js')

const configPaths = require('../config/paths.js')
const PORT = configPaths.ports.test
const { PORT = configPaths.ports.test } = process.env
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find this quite hard to read compared to e.g.

Suggested change
const { PORT = configPaths.ports.test } = process.env
cost PORT = process.env.PORT || configPaths.port

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry you've said this before, I'll change it 👍

We've got a couple of others:

https://github.com/alphagov/govuk-frontend/blob/main/config/jest/server/start.mjs#L6
https://github.com/alphagov/govuk-frontend/blob/main/lib/puppeteer-helpers.js#L5

It looks clearer with multiple envs perhaps?

const {
  ENV_1 = 'Fallback value 1',
  ENV_2 = 'Fallback value 2',
  ENV_3 = 'Fallback value 3',
  ENV_4 = 'Fallback value 4',
  ENV_5 = 'Fallback value 5'
} = process.env

* @param {string} screenshotName - Screenshot name
* @returns {Promise<void>}
*/
export async function screenshot (page, screenshotName) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a benefit to wrapping percySnapshot?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For JSDoc perhaps at the time, let's remove it

// Screenshot each component
const input = [...componentNames]

// Screenshot 4x components concurrently
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you arrive at 4x? Might be useful to capture in the commit message in case we want to revisit in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried 5x initially but 4x was faster

Good point though, worth trying 2x and 3x as well (you never know!)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you click into the Send screenshots to Percy job to see the timings:

The total action time varies due to GitHub cache retrieval API times being wobbly

I'll keep it at 4x but add a comment

@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3009 November 18, 2022 11:21 Inactive
colinrotherham added a commit that referenced this pull request Nov 18, 2022
Runs faster than “one at a time” by using multiple Chromium tabs. Once we go above 4x though we see little extra benefit

See: #3009 (comment)
@govuk-design-system-ci govuk-design-system-ci temporarily deployed to govuk-frontend-pr-3009 November 18, 2022 11:39 Inactive
Copy link
Member

@36degrees 36degrees left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can tidy up a dependency we no longer need, but otherwise this looks good to me 👍🏻

@@ -101,7 +101,7 @@ We generate 2 screenshots for each default example of every component. One examp

The screenshots are public, so you can check them without logging in. A BrowserStack account is needed to approve or reject any changes (if you don't have access, ask your tech lead for help). If you're the reviewer of the pull request code, it's your responsibility to approve or request changes for any visual changes Percy highlights.

When you run the tests locally (for example, using `npm test`), Percy commands are ignored and Percy does not generate any screenshots. You will see the following message in your command line output: `[percy] Percy is not running, disabling snapshots`.
When you run the tests locally (for example, using `npm run test:screenshots`), Percy commands are ignored and Percy does not generate any screenshots. You will see the following message in your command line output: `[percy] Percy is not running, disabling snapshots`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for keeping the docs in sync 🙌🏻

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@36degrees No problem. I didn't quite know if we should keep the test:* prefix

Based on the "…‘tests’ aren’t really tests” feedback

But we can always revisit another day. Thanks again 😊

@@ -1,51 +0,0 @@
const { join } = require('path')
const { fetch } = require('undici')
const { WebSocket } = require('ws')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we now remove ws from our dependencies? (Was introduced in 496cc38)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very nice, yep let's do that 🎉

Runs faster than “one at a time” by using multiple Chromium tabs. Once we go above 4x though we see little extra benefit

See: #3009 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants